package server.controller;

import static org.junit.Assert.fail;
import static pantherlot.testing.TestUtilities.Wait;
import static pantherlot.testing.TestUtilities.WaitShort;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import pantherlot.testing.ACMClone;
import pantherlot.testing.TestingSpots;
import server.storage.ParkingSpot;
import client.security.SecurityDisplay;
import client.security.SecurityLog;

public class AccessControlServerTest {

	static ACMClone acm_clone;
	static TestingSpots testing_spots;
	static SecurityDisplay security;
	
	static String student_id= "2223432";
	static String faculty_id= "1663314";
	static String handicap_id= "1654333";
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception 
	{
		acm_clone= new ACMClone();
		acm_clone.RunACMClone();
		Wait();
		
		testing_spots= new TestingSpots();
		WaitShort();
		
		Thread thread= new Thread(new Runnable() 
		{
			@Override
			public void run() 
			{
				security = new SecurityDisplay("localhost", 3738);
			}
		});
		thread.start();
		
		Wait();
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception 
	{
		
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void testIsConnectionAvailable_001() {
		if(acm_clone.server.isConnectionAvailable("315"))
			fail("Connection should be unavailable");
	}
	
	@Test
	public void testIsConnectionAvailable_002() {
		Wait();
		
		if(!acm_clone.server.isConnectionAvailable(testing_spots.student_parking_number))
			fail("Connection should be available");
	}

	@Test
	public void testReserveSpot_001() {
		ParkingSpot spot= acm_clone.garage.searchBySpotNumber(testing_spots.faculty_parking_number);
		acm_clone.server.reserveSpot(spot, faculty_id);
		
		WaitShort();
		
		spot= acm_clone.garage.searchBySpotNumber("101");
		
		if(!testing_spots.faculty_spot.isReserved())
			fail("Spot not reserved");
	}

	@Test
	public void testWrongUserDetected() 
	{
		acm_clone.server.wrongUserDetected("test");
		Wait();
		
		//tester must check popup to confirm success
	}

	@Test
	public void testDuplicateIdFound() {
		acm_clone.server.duplicateIdFound("test a", "test b");
		Wait();
		
		//tester must check popup to confirm success
	}

}
